package com.virus.server.http;

import com.virus.server.catalina.Context;

import java.util.*;

public class ApplicationContext extends BaseServletContext {

    private Context context;

    private Map<String, Object> attribute;

    public ApplicationContext(Context context) {
        this.context = context;
        attribute = new HashMap<>();
    }

    @Override
    public Object getAttribute(String s) {
        return attribute.get(s);
    }

    @Override
    public Enumeration<String> getAttributeNames() {
        Set<String> keySet = attribute.keySet();
        return Collections.enumeration(keySet);
    }

    @Override
    public void setAttribute(String s, Object o) {
        attribute.put(s, o);
    }

    @Override
    public void removeAttribute(String s) {
        attribute.remove(s);
    }

    @Override
    public String getRealPath(String s) {
        if (!s.startsWith("/") && !s.startsWith("\\") && !s.equals("")) {
            s = "/" + s;
        }
        return context.getDocBose() + s;
    }
}
